package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.FirmOrderBean;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Administrator on 2018/11/20.
 */

public class SubmitOrderAdapter extends BaseQuickAdapter<FirmOrderBean.ProductMapBean, BaseViewHolder> {

    public SubmitOrderAdapter(@Nullable List<FirmOrderBean.ProductMapBean> data) {
        super(R.layout.view_item_submit_order, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FirmOrderBean.ProductMapBean item) {
        ImageView ivIcon = helper.getView(R.id.iv_only_goods_icon);
        final String img_zt = item.getImg_zt();
        final String imgZt = item.getImgZt();
        if (!TextUtils.isEmpty(img_zt)) {
            final String[] img_ztarr = img_zt.trim().split(",");
            Glide.with(mContext).load(img_ztarr[0])
                    .transition(DrawableTransitionOptions.withCrossFade())//适用于Drawable
                    .into(ivIcon);
        } else if (!TextUtils.isEmpty(imgZt)) {
            final String[] img_ztarr = imgZt.trim().split(",");
            Glide.with(mContext).load(img_ztarr[0])
                    .transition(DrawableTransitionOptions.withCrossFade())//适用于Drawable
                    .into(ivIcon);
        } else {
            GlideUtils.loadImg(mContext, ivIcon, R.mipmap.logo);
        }
        if (!TextUtils.isEmpty(item.getTradename())) {
            helper.setText(R.id.tv_only_goods_title, item.getTradename());
        } else {
            helper.setText(R.id.tv_only_goods_title, item.getProductName());
        }
        helper.setText(R.id.tv_only_goods_info, item.getgName());
        helper.setText(R.id.tv_goods_price, getPrice(item));
        helper.setText(R.id.tv_count, "×" + item.getNum());
    }

    @NotNull
    private String getPrice(FirmOrderBean.ProductMapBean item) {
        String price = "";
        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
            price += "¥";
            price += item.getPrice();
        }
        if (!TextUtils.isEmpty(item.getMarketPrice()) && Double.parseDouble(item.getMarketPrice()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += item.getMarketPrice();
                price += "积分";
            } else {
                price += item.getMarketPrice();
                price += "积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "¥0.00";
        }
        return price;
    }
}
